package org.travel.app.common.util;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

/**
 * @author nmm
 * @date 2025-01-2025/1/10
 * @deriction njm......
 */
@Component
public class OrderStatusUtil implements ApplicationListener<ApplicationReadyEvent> {

    @Autowired
    RedisTemplate<String,Object> redisTemplate;

    @Override
    public void onApplicationEvent(ApplicationReadyEvent event) {
//        redisTemplate.opsForValue().set("orderCurrentStats", 1);
//        // 创建一个调度线程池
//        ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1);
//
//        // 定义任务
//        Runnable task = () -> {
//            redisTemplate.opsForValue().set("orderCurrentStats", 0);
//            // 任务执行后关闭调度器
//            scheduler.shutdown();
//        };
//
//        // 延迟 1 分钟后执行一次
//        scheduler.schedule(task, 30, TimeUnit.SECONDS);
    }
}